/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-1-4 21:53:17
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#include "tpsclient.h"

int g_blocksize; //消息块大小

net_reactor_t g_reactor_engine;

int main(int argc, char* argv[])
{
    const char* ip = NULL;
    int port = 0;
    if(argc > 3) {
        ip = argv[1];
        port = atoi(argv[2]);
        g_blocksize = atoi(argv[3]);
        
    } else {
        fprintf(stderr, "Usage: %s server_ip server_port block_size\n", argv[0]);
        return -1;
    }
    
    if(port <= 0 || port >= 65536)
    {
        fprintf(stderr, "Usage: %s server_ip server_port block_size\n", argv[0]);
        return -1;
    }
    

	CTPSClient* tpsClient = new CTPSClient(&g_reactor_engine);
	
    //CPPClient* ppClient_B = new CPPClient(&g_reactor_engine); //复用引擎
    
    g_reactor_engine.init_reactor(tpsClient, 4);
	tpsClient->startConnect(ip, port);

	//std::string str = "Net Reactor TPS Test!";

	char c;
	do{
		c = getchar();
		SLEEP_MS(100);

		if(c == 's' || c == 'S')
		{
			std::string msg = "";
			for(int i=0; i<g_blocksize; ++i)
			{
                msg.push_back('h');
				//msg.push_back(static_cast<char>(i%128));
			}
            
            tpsClient->send_data(msg.c_str(), (int)msg.length());
		}

		printf("Press q or Q to exit...\n");
	}while(c!='q' && c!='Q');

    g_reactor_engine.uninit_reactor(); //先反初始化
	SAFE_DELETE(tpsClient);
	return 0;
}


